﻿///////////////////////////////////////////////////////////////////////////////
// File Name: ButtonSkin.cpp
// Purpose: CButtonSkin 实现文件
// Author: 张东斌、ChongyangLee
// E_Mail: malutianshi7905@sina.com; ChongyangLee@hotmail.com
// History: 
// 2009/10/12 Mod 构造函数
// 
///////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ButtonSkin.h"

IMPLEMENT_SERIAL(CButtonSkin,CObjectSkin,1)


CButtonSkin::CButtonSkin(const char* szName)
:CObjectSkin(szName,keButtonSkin)
{
	m_fontButton = GetDefaultFont();
	m_bAutoFont = TRUE;
}

CButtonSkin::~CButtonSkin(void)
{
}
void CButtonSkin::Serialize(CArchive &ar)
{
	CObjectSkin::Serialize(ar);
	if(ar.IsStoring())
	{
		ar.Write(&m_fontButton,sizeof(m_fontButton));
		ar.Write(&m_bAutoFont,sizeof(m_bAutoFont));
		ar.Write(m_stateButton,sizeof(m_stateButton));
	}
	else
	{
		ar.Read(&m_fontButton,sizeof(m_fontButton));
		ar.Read(&m_bAutoFont,sizeof(m_bAutoFont));
		ar.Read(m_stateButton,sizeof(m_stateButton));
	}
}

void CButtonSkin::DrawButton(CDC *pDC, CRect rtDest,int nState)
{
	if(!DrawImageSection(pDC,rtDest,m_stateButton[nState].imageSkin))
	{
		if(!DrawImageSection(pDC,rtDest,m_stateButton[0].imageSkin))
		{
			pDC->Draw3dRect(rtDest,::GetSysColor(COLOR_BTNHILIGHT),::GetSysColor(COLOR_BTNHILIGHT));
			rtDest.DeflateRect(1,1);
			CBrush brush(GetSysColor(CTLCOLOR_BTN));
			pDC->FillRect(rtDest,&brush);
		}
	}
}